﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		TrackBackHelper.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 
using System.Text;
using System.Web.Mvc;
using Dexter.DataTransferObject;
using Dexter.Dependency;
using Dexter.Services;

namespace Dexter.Web.Mvc.Helpers {
	public static class TrackBackHelper {
		public static MvcHtmlString TrackBackRdf ( this HtmlHelper helper, PostDto item ) {
			IUrlBuilder u = DexterContainer.Resolve<IUrlBuilder> ( );
			var c = DexterContainer.Resolve<IConfigurationService> ( ).Configuration;

			if ( !c.Tracking.EnableTrackBackReceive ) {
				return MvcHtmlString.Empty;
			}

			StringBuilder sb = new StringBuilder ( );
			sb.Append ( "<!--" );
			sb.Append ( "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\">" );
			sb.AppendLine ( );
			sb.AppendFormat ( "<rdf:Description rdf:about=\"{0}\" dc:identifier=\"{0}\" dc:title=\"{1}\" trackback:ping=\"{2}\" />" , u.Post.Detail ( item ) , item.Title , u.TrackBackUrl ( item ) );
			sb.AppendLine ( "</rdf:RDF>" );
			sb.AppendLine ( "-->" );

			return MvcHtmlString.Create ( sb.ToString ( ) );
		}
	}
}
